$(function(){
		$("#allergyTable").datagrid({
			pagination:true,
			toolbar:'#tb',
			idField:"id"
		})
	})
	function allergyFormatter(value,row,index){
			return row.patient.name;
	}
	function allergySetCondition(){
		var postData = {drugName:$("#drugName").val()}
		var ids = $("#patient").combobox("getValue");
		postData["patient.id"] = ids;
		$("#allergyTable").datagrid("reload",postData);
	}
	function addAllergy(){
		addDialog("添加病人过敏史",500,400,"allergy/allergyFrom","#allergyForm","allergy/allergyAdd","#allergyTable");
	}
	
	
	function editAllergy(){
		var row = $("#allergyTable").datagrid("getSelected");
		if(row == null){
			$.messager.alert("提示","请选中要修改的数据行！","warning");
			return;
		}

		//如果选中了多个，只保留row这个
		$("#allergyTable").datagrid("clearSelections");
		$("#allergyTable").datagrid("selectRecord",row.id);
		
		var d = $("<div></div>").appendTo("body");
		d.dialog({
			title : "修改病人过敏史",
			iconCls : "icon-edit",
			width:500,
			height:400,
			modal:true,
			href : "allergy/allergyFrom",
			onClose:function(){$(this).dialog("destroy"); },
			onLoad:function(){
				//发送异步请求，查询数据
				$.post("allergy/allergyId",{id:row.id},function(data){
					$("#allergyForm").form("load",data);
					$("#patientid").combobox({disabled: true}); //下拉框的状态为禁用
					$("#patientid").combobox("select",data.patient.id);
					
				});
			},
			buttons:[{
				iconCls:"icon-ok",
				text:"确定",
				handler:function(){
					$("#allergyForm").form("submit",{
						url : "allergy/allergyEdit",
						success : function(data){
							d.dialog("close");
							$("#allergyTable").datagrid("reload");
						}
					});
				}
			},{
				iconCls:"icon-cancel",
				text:"取消",
				handler:function(){
					d.dialog("close");
				}
			}]
		})
	}
	
	//删除病人过敏史
	function deleteState(){
		deleteConfirm("#allergyTable","allergy/allergyEditState");
	}